{articles module="mission"  function="GetMissionOne" var="mission" id=$magic.request.id statx=$magic.request.statx }
     
	  {foreach from="$mission.submission" item="subval2"}
									
	<div class="row mg5" id="submission{$subval2.id}">
        <div class="col-sm-2 col-md-offset-1">
  			
    </div>
    <div class="col-sm-6">
  			<input type="text" value="{$subval2.name}" id="name{$subval2.id}" class="form-control"  {if  $_G.user_info.status ==1 }	{elseif $mission.status==3 && $mission.user_id == $_G.user_info.id} disabled {elseif $mission.user_id != $_G.user_info.id} disabled {/if} 	>
     
    </div>
    <div class="col-sm-1">
  			<input type="button" value="edit" onclick="updateSubMission({$subval2.id})"  class="btn btn-default">
     
    </div>
  </div>
  
		{/foreach}
	 
	  
	  
	  <div class="row mg5">
        <div class="col-sm-2 col-md-offset-1">
  			
    </div>
    <div class="col-sm-6">
  			<input type="text" value="" id="name" class="form-control"  {if  $_G.user_info.status ==1 }	{elseif $mission.status==3 && $mission.user_id == $_G.user_info.id} disabled {elseif $mission.user_id != $_G.user_info.id} disabled{/if}	>
     
    </div>
    <div class="col-sm-1">
  			<input type="button" value="add" onclick="addSubMission(this,{$magic.request.id},{$magic.request.statx})"  class="btn btn-default">
     
    </div>
  </div>
   {/articles}
	  <script>
	  	{literal}
		
		function updateSubMission(id)
		{
			var name = $("#name"+id).val();

			
			var url ="/?user&q=code/mission/editsub";
			var res = {
		
				name:name,
				id:id
				
			};
			
			
			$.post(url,res,function(data)
			{
				alert(data);
				if(data!='')
				{
					if(name=="")
					{
						$("#submission"+id).hide();
					}
				}
		
			},'text');
			
			}
			
			
			function addSubMission(obj,mission_id,statx){
	
	
	var name = $("#name").val();
//	var mission_id = $("input[name='mission_id']").val();
//	var statx = $("input[name='statx']").val();
	

	
	var url ="/?user&q=code/mission/addsub"
	var res = {
		
		mission_id:mission_id,
		name:name,
		statx:statx,
		
	};
	
	
//	alert(name+user_id+project_id);
	
		$.post(url,res,function(data)
		{
	
		alert(data.msg);
		if(data.msg == "ok")
		{
			
			var inlineHtml ='<div class="row mg5" id="submission'+data.mission_id+'"><div class="col-sm-2 col-md-offset-1"></div>';
				inlineHtml +='<div class="col-sm-6">';
					inlineHtml +='<input type="text" value="'+name+'" id="name'+data.mission_id+'" class="form-control">';
				inlineHtml +='</div>';
				inlineHtml +='<div class="col-sm-1">';
					inlineHtml +='<input type="button" value="edit" onclick="updateSubMission('+data.mission_id+')"  class="btn btn-default">';
					inlineHtml +='</div></div>';
//				inlineHtml += '<input type="button" value="edit" onclick="updateSubMission('+data.mission_id+')"  class="btn btn-default">';
			
			$(inlineHtml).insertBefore($(obj).parent().parent());
			
//			alert($(obj).parent().prev().children().html());
			$("#name").val("");
//			$(obj).parent().html(inlineHtml);
				
//			var inlineHtml2 = '<input type="text" value="" id="name'+data.mission_id+'" class="form-control">';
//			$(obj).parent().siblings(".col-sm-6").html(inlineHtml2);
		}

		},'json');
	
	
		return false;
		}

		{/literal}
	  </script>